<template>
    <view class="overflow-x-hidden bg-white">
        <view class="bg-gradual-nddyny" :style="'padding-top:'+$store.state.app.status_bar">
            <view class="padding-top-40 padding-lr-30 padding-bottom-20 flex align-center justify-between">
                <view class="flex align-center" @tap="$store.commit('userNavTo', '/user/info/info')">
                    <avatar ref="avatar" avatar_size="xl" avatar_url="my"></avatar>
                    <view class="margin-left-20">
                        <view class="text-white text-xl text-bold text-cut-2" style="width: 296rpx;">{{$store.state.user.identity_info.nickname}}</view>
                        <view class="text-black opacity8 text-sm flex flex-wrap" style="width: 296rpx;">
                            <view class="margin-right-10" v-if="$store.state.user.identity_info.is_seller == 1">商家</view>
                            <view class="margin-right-10" v-if="$store.state.user.identity_info.is_firm == 1">企业</view>
                            <view class="margin-right-10" v-if="$store.state.user.identity_info.is_city_partner == 1">城市合伙人</view>
                            <view class="margin-right-10" v-if="$store.state.user.identity_info.is_region_agent == 1">区域代理</view>
                            <view class="margin-right-10" v-if="$store.state.user.identity_info.is_promoter == 1">推广专员</view>
                        </view>
                    </view>
                </view>
                <view @tap="$store.commit('userNavTo', '/user/info/setting')" class="light bg-nddyny round padding-lr-40 padding-tb-20 flex flex-sub margin-left-20"
                    style="margin-right: -60rpx;">
                    <view class="text-xl text-black opacity8 flex align-center">
                        <text class="cuIcon-settings"></text>
                        <text class="text-df margin-lr-10">个人设置</text>
                        <text class="cuIcon-right"></text>
                    </view>
                </view>
            </view>
            <nGrid :row="grid_user_asset.row" :col="grid_user_asset.col" :border="grid_user_asset.border" :list="grid_user_asset.list"
                :value_info.sync="$store.state.user.user_asset_info" class_name="text-black opacity8" class_value="margin-top-10"
                style="background-color: transparent;">
            </nGrid>
        </view>
        <nBar title="常用功能"></nBar>
        <nGrid row="1" col="4" :border="false" :list="btn.user" style="margin-top: -40rpx;"></nGrid>
        <nBar title="资产管理"></nBar>
        <nGrid row="1" col="5" :border="false" :list="btn.user_asset" style="margin-top: -40rpx;"></nGrid>
        <nFormButton v-if="$store.state.user.identity_info.is_apply_seller_user_id=='1'" title="我的商家账号" button_class="radius-16"
            uri="/seller/user/list"></nFormButton>
        <nFormButton v-if="user_login_info && $store.state.user.is_seller_firm == 1" title="切换到用户账号" button_class="radius-16"
            :tap="()=>{changeLogin()}"></nFormButton>
        <template v-if="$store.state.user.identity_info.is_seller=='1'">
            <nBar title="商家管理"></nBar>
            <nGrid row="1" col="5" :border="false" :list="btn.seller" style="margin-top: -40rpx;"></nGrid>
            <nFormButton title="收款二维码" :tap="()=>{face_pay_qrcode_dialog.show = true}"></nFormButton>
        </template>
        <nBar title="我的订单" right_title="查看全部" right_uri="/seller/item/order/list"></nBar>
        <nGrid row="1" col="5" :border="false" :list="btn.order" style="margin-top: -40rpx;"></nGrid>
        <modalDialog v-if="$store.state.user.identity_info.is_seller=='1'" :is_hide_cancel="true" :show.sync="face_pay_qrcode_dialog.show"
            title="收款二维码">
            <template #content>
                <tkiQrcode ref="tkiQrcode" :size="520" class="margin-lr-50" :val="face_pay_qrcode_val" :icon="face_pay_qrcode_icon"
                    :iconSize="60" :onval="true" :loadMake="true" :showLoading="false">
                </tkiQrcode>
            </template>
        </modalDialog>
    </view>
</template>

<script>
    import tkiQrcode from "@/components/tki-qrcode/tki-qrcode.vue"
    export default {
        components: {
            tkiQrcode
        },
        props: ['params'],
        data() {
            let grid_user_asset = this.$store.state.user.is_seller_firm == 1 ?
                this.$user.grid.seller_user_asset :
                this.$user.grid.user_asset;
            return {
                grid_user_asset,
                user_login_info: uni.getStorageSync('user_login_info') ? true : false,
                service_phone: '0571-86707589',
                face_pay_qrcode_dialog: {
                    show: false,
                },
                btn: {
                    user: [{
                        name: '每日奖励',
                        icon: 'remind',
                        color: 'deep-nddyny',
                        uri: '/user/asset/dailyBonus'
                    }, {
                        name: '每日任务',
                        icon: 'creative',
                        color: 'deep-nddyny',
                        uri: '/user/asset/creditScore'
                    }, {
                        name: '推广中心',
                        icon: 'friend',
                        color: 'deep-nddyny',
                        uri: '/user/promote/list'
                    }, {
                        name: '消费余额',
                        icon: 'redpacket',
                        color: 'deep-nddyny',
                        uri: '/user/pay/advpay'
                    }, ],
                    user_asset: [{
                        name: '资产日志',
                        icon: 'baby',
                        color: 'deep-nddyny',
                        uri: '/user/asset/log'
                    }, {
                        name: '申请提现',
                        icon: 'refund',
                        color: 'deep-nddyny',
                        uri: '/user/asset/withdraw'
                    }, {
                        name: '推广奖励',
                        icon: 'ticket',
                        color: 'deep-nddyny',
                        uri: '/user/asset/promote'
                    }, {
                        name: '我的礼包',
                        icon: 'present',
                        color: 'deep-nddyny',
                        uri: '/user/promote/gift/payList'
                    }, {
                        name: '我的合约',
                        icon: 'form',
                        color: 'deep-nddyny',
                        uri: '/user/asset/seeder'
                    }],
                    seller: [{
                        name: '当面支付',
                        icon: 'pay',
                        color: 'deep-nddyny',
                        uri: '/seller/facePayList?is_manage=1'
                    }, {
                        name: '店铺信息',
                        icon: 'shop',
                        color: 'orange',
                        uri: '/seller/info'
                    }, {
                        name: '商品管理',
                        icon: 'clothes',
                        color: 'orange',
                        uri: '/seller/item/list'
                    }, {
                        name: '商家订单',
                        icon: 'copy',
                        color: this.$store.state.user.identity_info.is_seller == '1' ? 'orange' : '',
                        uri: this.$store.state.user.identity_info.is_seller == '1' ?
                            '/seller/item/order/list?is_manage=1&seller_type=0' : ''
                    }, {
                        name: '企业订单',
                        icon: 'copy',
                        color: this.$store.state.user.identity_info.is_firm == '1' ? 'orange' : '',
                        uri: this.$store.state.user.identity_info.is_firm == '1' ?
                            '/seller/item/order/list?is_manage=1&seller_type=1' : ''
                    }],
                    order: [{
                        name: '当面支付',
                        icon: 'pay',
                        color: 'deep-nddyny',
                        uri: '/seller/facePayList'
                    }, {
                        name: '待接单',
                        icon: 'vipcard',
                        color: 'orange',
                        uri: '/seller/item/order/list?order_type=0'
                    }, {
                        name: '待发货',
                        icon: 'send',
                        color: 'orange',
                        uri: '/seller/item/order/list?order_type=1'
                    }, {
                        name: '待收货',
                        icon: 'deliver',
                        color: 'orange',
                        uri: '/seller/item/order/list?order_type=2'
                    }, {
                        name: '取消 / 退款',
                        icon: 'sponsor',
                        color: 'orange',
                        uri: '/seller/item/order/list?order_type=4'
                    }]
                }
            }
        },
        created() {
            if (this.params && this.params.is_login == 1) {
                this.params.is_login = 0;
                // #ifdef APP-PLUS
                plus.push.getClientInfoAsync((info) => {
                    this.$api.post(this, {
                        url: '/alone/getuiCid',
                        data_key: null,
                        data_append: {
                            getui_cid: info.clientid,
                        },
                        success: (Result) => {
                            if (this.$R.noSuccess(Result)) return;
                        }
                    });
                }, err => {});
                // #endif
            }
        },
        watch: {
            '$store.state.user.identity_info.avatar'() {
                this.$refs.avatar.setTrueAvatarUrl();
            },
        },
        computed: {
            face_pay_qrcode_val() {
                return this.$app.app_url +
                    '/pages/seller/item/list?is_face_pay=1&seller_id=' +
                    this.$store.state.user.identity_info.user_id
            },
            face_pay_qrcode_icon() {
                if (this.$store.state.user.identity_info.seller_info.logo) {
                    return this.$app.oss_base_url + this.$store.state.user.identity_info.seller_info.logo +
                        '?x-oss-process=image/resize,m_fixed,limit_0,h_60,w_60';
                } else {
                    return '/static/image/logo/122x122.png';
                }
            }
        },
        methods: {
            callServicePhone() {
                uni.makePhoneCall({
                    phoneNumber: this.service_phone
                });
            },
            changeLogin() {
                this.$store.commit('userChangeLoginUser');
            }
        }
    }
</script>
